/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package compiledriver;

import java.util.ArrayList;
import java.util.ListIterator;

/**
 *
 * <p>A <code>Definition</code> class which creates definitions for methods that
 * contain a name and arguments.</p>
 */
public class Definition {
    
    protected String id;
    protected ArrayList<Expression> argList = new ArrayList<Expression>();
    public Definition (ListIterator<String> intext)
    {
        id = intext.next();

        if (intext.next().equals("("))
        {
            boolean continueLoop = true;
            while (continueLoop)
            {
                String nxt = intext.next();
                if (nxt.equals(")"))
                {
                    continueLoop = false;
                }
                else
                {
                    intext.previous();
                    argList.add(new Expression(intext));
                }
            }
        }
    }

   
    

    /**
     * <p>Returns the Id of the class</p>
     * @return the Id as a <code>String</code>
     */
    public String getId()
    {
        return id;
    }

    @Override
    public String toString()
    {
        StringBuilder sb = new StringBuilder();
        sb.append(id);
        for (Expression expr : argList)
        {
            sb.append(expr.toString());
        }
        return sb.toString();
    }
}
